package aryn.mapEditor;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.Popup;
import javax.swing.PopupFactory;

import aryn.framework.display.MyPanel;
import aryn.mapEditor.Menu.choose;

public class MyPopup extends MyPanel {
	private static final long serialVersionUID = 1L;
	
	private Popup popup;
	
	public MyPopup(final Menu owner, int x, int y) {
		super(x, y, 460, 100);
		popup = PopupFactory.getSharedInstance().getPopup(owner, this, x, y);
		popup.show();
		this.setBorder(BorderFactory.createLineBorder(Color.black));
		
		JButton append = new JButton();
		append.setToolTipText("Appends the actual tileset to the right. Use the panel arrows to move.");
		append.setText("Append");
		append.setSize(100, 30);
		append.setLocation(10, 50);
		append.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				owner.setAnswer(choose.APPEND);
				popup.hide();
			}
		});
		add(append);
		
		JButton replace = new JButton();
		replace.setToolTipText("Replaces last tileset with the current one.");
		replace.setText("Replace");
		replace.setSize(110, 30);
		replace.setLocation(120, 50);
		replace.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				owner.setAnswer(choose.REPLACE);
				popup.hide();
			}
		});
		add(replace);
		
		JButton exclusive = new JButton();
		exclusive.setToolTipText("Replaces all the tilesets loaded with the current one.");
		exclusive.setText("Exclusive");
		exclusive.setSize(100, 30);
		exclusive.setLocation(240, 50);
		exclusive.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				owner.setAnswer(choose.EXCLUSIVE);
				popup.hide();
			}
		});
		add(exclusive);
		
		JButton cancel = new JButton();
		cancel.setToolTipText("No variations are taken.");
		cancel.setText("Cancel");
		cancel.setSize(100, 30);
		cancel.setLocation(350, 50);
		cancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				owner.setAnswer(choose.CANCEL);
				popup.hide();
			}
		});
		add(cancel);
	}
	
	public void postRender(Graphics g) {
		g.drawString("Choose how you want to load your tileset.", 100, 30);
	}
}
